import Router from '@koa/router';
import { Rcontext } from '../index';
import { uploadFile } from '../utils/upload';
import { imgUrlPrefix } from '../config/app';

const uploadRouter = new Router();

uploadRouter.post('/upload', async (ctx: Rcontext) => {
  const filePath = await uploadFile(ctx.request.files.file, ctx.request.body.type);
  ctx.send(imgUrlPrefix() + filePath);
});

export default uploadRouter;
